package com.gsafety.wellsfort.service.course;

import com.gsafety.wellsfort.domain.model.knowledge.AnswerOption;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class AnswerOptionUtils {
    public static String parseOptionToString(List<AnswerOption> answerOptionList) {
        String lastResult = "";
        StringBuffer myOptionStr = new StringBuffer();
        for (AnswerOption tmpOpt : answerOptionList) {
            myOptionStr.append(tmpOpt.getOptionText());
            myOptionStr.append(",");
        }
        if (myOptionStr.length() > 0) {
            lastResult = myOptionStr.substring(0, myOptionStr.length() - 1);
        }
        return lastResult;

    }

    public static String parseOptionIdToString(List<AnswerOption> answerOptionList) {
        String lastResult = "";
        StringBuffer myOptionStr = new StringBuffer();
        for (AnswerOption tmpOpt : answerOptionList) {
            myOptionStr.append(tmpOpt.getId());
            myOptionStr.append(",");
        }
        if (myOptionStr.length() > 0) {
            lastResult = myOptionStr.substring(0, myOptionStr.length() - 1);
        }
        return lastResult;

    }
    public static Set<String> parseOptionIdToHashSet(List<AnswerOption> answerOptionList) {
        Set<String> set=new HashSet<String>();
        for (AnswerOption tmpOpt : answerOptionList) {
            set.add(tmpOpt.getId()+"");
        }
        return set;

    }
    public static List<String> stringToList (String strArr){
        return Arrays.stream(strArr.split(","))
                .collect(Collectors.toList());
    }
}
